package com.bdd.jpa.controller;

import com.bdd.jpa.entity.dto.MessageDto;
import com.bdd.jpa.service.message.MessageService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Bdd
 * @Description
 *
*          测试消息Controller
 *      事务没有添加
 *
 * @Date 2019/9/23 16:03
 */
@RequestMapping("message")
@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 添加消息
     * @param messageDto  用于
     * @return
     */
    @PostMapping("save")
    public ResponseEntity save(@RequestBody MessageDto messageDto) throws Exception {
        messageService.save(messageDto);
        return ResponseEntity.ok().body("添加成功");
    }


    /**
     * 修改消息
     * @param messageDto
     * @return
     */
    @PostMapping("update")
    public ResponseEntity update(@RequestBody MessageDto messageDto) throws Exception {
        messageService.update(messageDto);
        return ResponseEntity.ok().body("修改成功");
    }


    /**
     * 删除消息
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResponseEntity delete(@PathVariable Long id) throws SchedulerException, JsonProcessingException {
        messageService.delete(id);
        return ResponseEntity.ok().body("删除成功");
    }


    /**
     * 查询消息
     * @param id
     * @return
     */
    @GetMapping("details/{id}")
    public ResponseEntity details(@PathVariable Long id){
        return ResponseEntity.ok().body(messageService.details(id));
    }


    /**
     * 列表
     * @return
     */
    @GetMapping("list")
    public ResponseEntity list(){
        return ResponseEntity.ok().body(messageService.list());
    }






}
